package cc.mrbird.febs.common.datasource.starter.organization;

import com.xf.common.core.constant.CommonConstants;
import feign.RequestInterceptor;
import feign.RequestTemplate;
import lombok.extern.slf4j.Slf4j;
import org.springframework.util.StringUtils;

/**
 * @author lengleng
 * @date 2018/9/14
 */
@Slf4j
public class FeignOrganizationInterceptor implements RequestInterceptor {

    @Override
    public void apply(RequestTemplate requestTemplate) {
        if (OrganizationContextHolder.getOrganizationConfig() == null || StringUtils.isEmpty(OrganizationContextHolder.getOrganizationId())) {
            //log.debug("TTL 中的 租户ID为空，feign拦截器 >> 跳过");
            return;
        }
        //本次调用链接，是否使用租户
        requestTemplate.header(CommonConstants.ORGANIZATION_ID, OrganizationContextHolder.getOrganizationId());
        requestTemplate.header(CommonConstants.ORGANIZATION_FLAG, OrganizationContextHolder.getOrganizationFlag().toString());
    }

}
